//
//  MainPageViewController.m
//  GSG
//
//  Created by dllo on 15/4/21.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "MainPageViewController.h"
#import"SDCycleScrollView.h"
#import"MusicLibraryViewController.h"
#import"SixClassViewController.h"
#import"AFNetworking.h"
#import"AFNetworkingTool.h"
#import"UIImageView+WebCache.h"
#import "RecommendViewController.h"
#import"SearchViewController.h"
#import "LandingViewController.h"
#import "IIViewDeckController.h"
#import "RightViewController.h"
#import "CycleScrollViewController.h"
#import"PlayListViewController.h"
#import "CollectViewController.h"
@interface MainPageViewController ()<SDCycleScrollViewDelegate>

@property(nonatomic,retain)UIImageView *imageview;
@property(nonatomic,retain)NSArray*arrPoster;
@property(nonatomic,retain)NSMutableArray *arrURL;
@property(nonatomic,retain)NSMutableArray *arrID;
@property(nonatomic,retain)NSMutableArray *arrurl;@end

@implementation MainPageViewController

-(void)dealloc{
    [_imageview release];
    [_arrURL release];
    [_arrPoster release];
    [_arrID release];
    [_arrurl release];
    [super dealloc];
}

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.arrURL=[NSMutableArray array];
        self.arrID=[NSMutableArray array];
        self.arrurl=[NSMutableArray array];    }
    return self;
}

-(void)topButtonClickHandler:(id)sender
{
    [self.viewDeckController toggleTopViewAnimated:YES];
}

-(void)bottomButtonClickHandler:(id)sender
{
    [self.viewDeckController toggleBottomViewAnimated:YES];
}

-(void)rightButtonClickHandler:(id)sender
{
    [self.viewDeckController toggleRightViewAnimated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
 
    
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height)];
    [image setImage:[UIImage imageNamed:@"beijing.png"]];
    [self.view addSubview:image];
    //轮播矿背景
    UIView *viewScroll=[[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height * 350 / 667, self.view.frame.size.width, self.view.frame.size.height * 200 / 667)];
    viewScroll.backgroundColor=[UIColor grayColor];
    viewScroll.alpha = 0.3;
    [self.view addSubview:viewScroll];
    [viewScroll release];
    
    //专题的6个button
    UIButton *bu1=[UIButton buttonWithType:UIButtonTypeCustom];
    bu1.frame = CGRectMake(self.view.frame.size.width * 65 / 375, self.view.frame.size.height * 115 / 667, self.view.frame.size.width * 65 / 375, self.view.frame.size.height * 65 / 667);
    [bu1 setImage:[UIImage imageNamed:@"changjing.png"] forState:UIControlStateNormal];
    [self.view addSubview:bu1];
    [bu1 addTarget:self action:@selector(actionBu1) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIButton *bu2=[UIButton buttonWithType:UIButtonTypeCustom];
    bu2.frame = CGRectMake(self.view.frame.size.width * 255 / 375, self.view.frame.size.height * 115 / 667, self.view.frame.size.width * 65 / 375, self.view.frame.size.height * 65 / 667);
    [bu2 setImage:[UIImage imageNamed:@"yuyan.png"] forState:UIControlStateNormal];
    [self.view addSubview:bu2];
    [bu2 addTarget:self action:@selector(actionBu2) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIButton *bu3=[UIButton buttonWithType:UIButtonTypeCustom];
    bu3.frame = CGRectMake(self.view.frame.size.width * 160 / 375, self.view.frame.size.height * 115 / 667, self.view.frame.size.width * 65 / 375, self.view.frame.size.height * 65 / 667);
    [bu3 setImage:[UIImage imageNamed:@"xinqing.png"] forState:UIControlStateNormal];
    [self.view addSubview:bu3];
    [bu3 addTarget:self action:@selector(actionBu3) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIButton *bu4=[UIButton buttonWithType:UIButtonTypeCustom];
    bu4.frame = CGRectMake(self.view.frame.size.width * 65 / 375, self.view.frame.size.height * 205 / 667, self.view.frame.size.width * 65 / 375, self.view.frame.size.height * 65 / 667);
    [bu4 setImage:[UIImage imageNamed:@"fengge.png"] forState:UIControlStateNormal];
    [self.view addSubview:bu4];
    [bu4 addTarget:self action:@selector(actionBu4) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIButton *bu5=[UIButton buttonWithType:UIButtonTypeCustom];
    bu5.frame = CGRectMake(self.view.frame.size.width * 255 / 375, self.view.frame.size.height * 205 / 667, self.view.frame.size.width * 65 / 375, self.view.frame.size.height * 65 / 667);
    [bu5 setImage:[UIImage imageNamed:@"tese.png"] forState:UIControlStateNormal];
    [self.view addSubview:bu5];
    [bu5 addTarget:self action:@selector(actionBu5) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIButton *bu6=[UIButton buttonWithType:UIButtonTypeCustom];
    bu6.frame = CGRectMake(self.view.frame.size.width * 160 / 375, self.view.frame.size.height * 205 / 667, self.view.frame.size.width * 65 / 375, self.view.frame.size.height * 65 / 667);
    [bu6 setImage:[UIImage imageNamed:@"niandai.png"] forState:UIControlStateNormal];
    [self.view addSubview:bu6];
    [bu6 addTarget:self action:@selector(actionBu6) forControlEvents:UIControlEventTouchUpInside];
    
    //乐库按钮
    UIButton *BuMusicLibrary=[UIButton buttonWithType:UIButtonTypeSystem];
    BuMusicLibrary.frame=CGRectMake(self.view.frame.size.width * 169 / 375, self.view.frame.size.height * 300 / 667, self.view.frame.size.width * 40 / 375 , self.view.frame.size.height * 30 / 667);
    [BuMusicLibrary setTitle:@"乐库" forState:UIControlStateNormal];
    [BuMusicLibrary setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [BuMusicLibrary addTarget:self action:@selector(actionBuMusicLibrary) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:BuMusicLibrary];
    
    //登陆按钮
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"播放" style:UIBarButtonItemStyleDone target:self action:@selector(actionBuLand)];
    self.navigationItem.rightBarButtonItem.tintColor=[UIColor whiteColor];
    
    //搜索按钮
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"搜索" style:UIBarButtonItemStyleDone target:self action:@selector(actionSearch)];
    self.navigationItem.leftBarButtonItem.tintColor=[UIColor whiteColor];
//    UILabel *recommend=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width * 5 / 375, self.view.frame.size.height * 350 / 667, self.view.frame.size.width * 40 / 375, self.view.frame.size.height * 30 / 667)];
//    recommend.text=@"推荐";
//    recommend.tintColor=[UIColor whiteColor];
//    [self.view addSubview:recommend];
//    [recommend release];
    UIButton *Bu=[UIButton buttonWithType:UIButtonTypeSystem];
    Bu.frame=CGRectMake(self.view.frame.size.width * 5 / 375, self.view.frame.size.height * 350 / 667, self.view.frame.size.width * 40 / 375, self.view.frame.size.height * 30 / 667);
    [Bu setTitle:@"收藏" forState:UIControlStateNormal];
    [Bu setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [Bu addTarget:self action:@selector(button) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:Bu];
    
    
    UIButton *BuRecommend=[UIButton buttonWithType:UIButtonTypeSystem];
    BuRecommend.frame=CGRectMake(self.view.frame.size.width * 330 / 375, self.view.frame.size.height * 350 / 667, self.view.frame.size.width * 40 / 375, self.view.frame.size.height * 30 / 667);
    [BuRecommend setTitle:@"更多" forState:UIControlStateNormal];
    [BuRecommend setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [BuRecommend addTarget:self action:@selector(actionRecommend) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:BuRecommend];
    
    // 网络加载 --- 创建带标题的图片轮播器
    SDCycleScrollView *cycleScrollView2 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(self.view.frame.size.width * 15 / 375, self.view.frame.size.height * 380 / 667, self.view.frame.size.width - (self.view.frame.size.width * 30 / 375), self.view.frame.size.height * 140 / 667) imageURLsGroup:nil];
    cycleScrollView2.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    cycleScrollView2.delegate=self;
    cycleScrollView2.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
    cycleScrollView2.dotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
    [self.view addSubview:cycleScrollView2];
    cycleScrollView2.autoScrollTimeInterval = 4.0;
    
    //4.0 影响播放的效果 可以改变数字
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        cycleScrollView2.imageURLsGroup = self.arrURL;
        
    });
    
    NSString *urlRecommendPoster=@"http://online.dongting.com/recomm/recomm_modules?&app=ttpod&v=v7.7.0.2015012818&uid=&mid=iPhone4&f=f320&s=s310&imsi=&hid=&splus=7.1.1&active=1&net=2&openudid=ad6f50f586818c4f36ff4358053c1b53fee58cdf&idfa=E2EAC64B-1F1C-4AC5-A0E1-8BE37A03FB96&utdid=VTCyBQSkYzwDAALO9zZTFfPC&alf=201200&version=1429340403";
    [ AFNetworkingTool NetWorkingTooStr:urlRecommendPoster block:^(id result) {
        NSDictionary *dic=[result objectForKey:@"data"];
        NSArray*arrPosters=[dic objectForKey:@"posters"];
        NSDictionary*dic1=arrPosters[0];
        self.arrPoster=[dic1 objectForKey:@"data"];
        
        for(int i=0;i<self.arrPoster.count ;i++)
        {
            NSString *str=[self.arrPoster[i] objectForKey:@"pic_url"];
            NSURL *url = [NSURL URLWithString:str];
            [self.arrURL  addObject:url ];
            NSString *str1=[self.arrPoster[i] objectForKey:@"_id"];
            [self.arrID addObject:str1];
            
            NSString *str2=[self.arrPoster[i] objectForKey:@"url"];
            [self.arrurl addObject:str2];
        }
    }];
    
}
// 收藏
- (void)button{
    CollectViewController *coll = [[CollectViewController alloc] init];
    [self.navigationController pushViewController:coll animated:YES];
    [coll release];
}

-(void)actionBu1{
    
    SixClassViewController *scvc=[[SixClassViewController alloc]init];
    [self.navigationController pushViewController:scvc animated:YES];
    scvc.strTitle=@"场景";
    [scvc release];
    
}
-(void)actionBu2{
    
    SixClassViewController *scvc=[[SixClassViewController alloc]init];
    [self.navigationController pushViewController:scvc animated:YES];
    scvc.strTitle=@"语言";
    [scvc release];
}
-(void)actionBu3{
    
    SixClassViewController *scvc=[[SixClassViewController alloc]init];
    [self.navigationController pushViewController:scvc animated:YES];
    scvc.strTitle=@"心情";
    [scvc release];
}
-(void)actionBu4{
    
    SixClassViewController *scvc=[[SixClassViewController alloc]init];
    [self.navigationController pushViewController:scvc animated:YES];
    scvc.strTitle=@"风格";
    [scvc release];
}
-(void)actionBu5{
    
    SixClassViewController *scvc=[[SixClassViewController alloc]init];
    [self.navigationController pushViewController:scvc animated:YES];
    scvc.strTitle=@"特色";
    [scvc release];
}
-(void)actionBu6{
    
    SixClassViewController *scvc=[[SixClassViewController alloc]init];
    [self.navigationController pushViewController:scvc animated:YES];
    scvc.strTitle=@"年代";
    [scvc release];
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    CycleScrollViewController *csvc=[[CycleScrollViewController alloc]init];
    
    csvc.ID=self.arrID[index];
    csvc.url=self.arrurl[index];
    
    [self.navigationController pushViewController:csvc animated:YES];
    
    [csvc release];




}

-(void)actionBuMusicLibrary{
    
    MusicLibraryViewController *mlvc=[[MusicLibraryViewController alloc]init];
    [self.navigationController pushViewController:mlvc animated:YES
     ];
}

-(void)actionBuLand{
    PlayListViewController *plvc=[[PlayListViewController alloc]init];
    [self.navigationController pushViewController:plvc animated:YES];
    [plvc release];

}

-(void)actionSearch{
    SearchViewController *svc=[[SearchViewController alloc]init];
    [self.navigationController pushViewController:svc animated:YES];
    [svc release];
}

-(void)actionRecommend{
    RecommendViewController *rcc=[[RecommendViewController alloc]init];
    [self.navigationController pushViewController:rcc animated:YES];
    [rcc release];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
